//
//  GroupBuyingViewController.m
//  PeopleStreet
//
//  Created by 辰领科技 on 16/6/6.
//  Copyright © 2016年 yuf. All rights reserved.
//

#import "GroupBuyingViewController.h"
#import "GroupBuyingTableViewCell.h"

static NSString * cellIndentifier = @"GroupBuyingTableViewCell";

@interface GroupBuyingViewController ()
<UITableViewDelegate,UITableViewDataSource>

@property (strong, nonatomic) IBOutlet UIView *navView;
@property (strong, nonatomic) IBOutlet UITableView *tableView;
@property (strong, nonatomic) IBOutlet UIView *buttonView;
@property (strong, nonatomic) IBOutlet UIButton *oneButton;
@property (strong, nonatomic) IBOutlet UIButton *twoButton;
@property (strong, nonatomic) IBOutlet UIButton *threeButton;
@property (strong, nonatomic) IBOutlet UIButton *fourButton;
@property (strong, nonatomic) IBOutlet UIView *sliderView;



@end

@implementation GroupBuyingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initViewLayout];
}


- (void)initViewLayout{
    [self adaptiveViewLayout:self.view];
    [self adaptiveViewLayout:self.navView];
    [self adaptiveViewLayout:self.buttonView];
   
    _sliderView.frame = flexibleFrame(CGRectMake(0, 39.5, 80, 1.5), YES);
    
    [self.tableView registerNib:[UINib nibWithNibName:cellIndentifier bundle:nil] forCellReuseIdentifier:cellIndentifier];
    
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    
    
}
#pragma mark - 切换TableView
- (IBAction)switchTableViewButton:(UIButton *)sender {
    if (sender == _oneButton) {
        _oneButton.selected = YES;
        _twoButton.selected = NO;
        _threeButton.selected = NO;
        _fourButton.selected = NO;
        [UIView animateWithDuration:0.2 animations:^{
            _sliderView.frame = flexibleFrame(CGRectMake(0, 39.5, 80, 1.5), YES);
        }];
 
    } else if (sender == _twoButton){
        _oneButton.selected = NO;
        _twoButton.selected = YES;
        _threeButton.selected = NO;
        _fourButton.selected = NO;
        [UIView animateWithDuration:0.2 animations:^{
            _sliderView.frame = flexibleFrame(CGRectMake(80, 39.5, 80, 1.5), YES);
        }];
    } else if (sender == _threeButton){
        _oneButton.selected = NO;
        _twoButton.selected = NO;
        _threeButton.selected = YES;
        _fourButton.selected = NO;
        [UIView animateWithDuration:0.2 animations:^{
            _sliderView.frame = flexibleFrame(CGRectMake(160, 39.5, 80, 1.5), YES);
        }];
        
    } else if (sender == _fourButton){
        _oneButton.selected = NO;
        _twoButton.selected = NO;
        _threeButton.selected = NO;
        _fourButton.selected = YES;
        [UIView animateWithDuration:0.2 animations:^{
            _sliderView.frame = flexibleFrame(CGRectMake(240, 39.5, 80, 1.5), YES);
        }];
        
    }


}

#pragma mark - 返回
- (IBAction)back:(id)sender {
    [self.navigationController  popViewControllerAnimated:YES];
}

#pragma mark - UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 10;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 77*VerticalRatio();
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}


- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 45;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView * view = [[UIView alloc]initWithFrame:flexibleFrame(CGRectMake(0, 0, 320, 45), NO)];
    view.backgroundColor = [UIColor whiteColor];

    UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = flexibleFrame(CGRectMake(258, 10, 54, 20), NO);
    button.layer.cornerRadius = 4*VerticalRatio();
    button.layer.borderWidth = 1;
    button.layer.borderColor  = [UIColor colorWithRed:1.000 green:0.667 blue:0.086 alpha:1.000].CGColor;

    button.tag = 200+section;
    NSString  * status = @"1";
    if ([status isEqualToString:@"1"]) {
        status = @"申请上线";
    }else if([status isEqualToString:@"2"]){
        status = @"申请下线";
    }else if([status isEqualToString:@"3"]){
        status = @"发布上线";
    }
    [button setTitle:status forState:UIControlStateNormal];
    [button setTitleColor:[UIColor colorWithRed:1.000 green:0.667 blue:0.086 alpha:1.000] forState:UIControlStateNormal];
    button.titleLabel.font = [UIFont systemFontOfSize:13*VerticalTexeRatio()];
//    [button addTarget:self action:@selector(sectionButtonHandel:) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:button];

    UILabel * line = [[UILabel alloc]initWithFrame:flexibleFrame(CGRectMake(0, 40, 320, 5), NO)];
    line.backgroundColor = [UIColor colorWithWhite:0.957 alpha:1.000];
    [view addSubview:line];
    
    return view;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    GroupBuyingTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIndentifier];
    if (cell == nil) {
        cell= [[GroupBuyingTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIndentifier];
        
    }
    
    
    return cell;
    
    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (UIView *)sliderView {
    if (!_sliderView) {
        _sliderView = [[UIView alloc]initWithFrame:flexibleFrame(CGRectMake(0, 39, 80, 1), NO)];
    }
    return _sliderView;
}

@end
